﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MediaPlayer
{
	public partial class VolBarControl : UserControl
	{
        public delegate void VolChangedHandler(object sender);

        public event VolChangedHandler VolChanged; 

        private Path[] volPaths;

        private int _volLevel;
        public int VolLevel
        {
            set
            {
                if (_volLevel == value)
                {
                    return;
                }
                _volLevel = value;
                VolChanged(this);
                GoToState(VolLevel);
            }
            get
            {
                return _volLevel;
            }
        }

		public VolBarControl()
		{
			// Required to initialize variables
			InitializeComponent();
            volPaths = new Path[] { vol1, vol2, vol3, vol4, vol5, vol6 };
		}

		private void OnVol1LeftBtnUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
			// TODO: Add event handler implementation here.
            VolLevel = 1;
		}

		private void OnVol2LeftBtnUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
            // TODO: Add event handler implementation here.
            VolLevel = 2;
		}

		private void OnVol3LeftBtnUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
            // TODO: Add event handler implementation here.
            VolLevel = 3;
		}

		private void OnVol4LeftBtnUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
            // TODO: Add event handler implementation here.
            VolLevel = 4;
		}

		private void OnVol5LeftBtnUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
            // TODO: Add event handler implementation here.
            VolLevel = 5;
		}

		private void OnVol6LeftBtnUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
		{
            // TODO: Add event handler implementation here.
            VolLevel = 6;
		}

        private void LayoutRoot_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (e.Delta > 0)
            {
                if (VolLevel < 6)
                {
                    VolLevel++;
                }
            }
            else if (e.Delta < 0)
            {
                if (VolLevel > 0)
                {
                    VolLevel--;
                }
            }
        }

        private void GoToState(int state)
        {
            string statename = "lv" + state;
            try
            {
                VisualStateManager.GoToState(this, statename, true);
            }
            catch (ArgumentNullException ex)
            {
            	
            }
        }
	}
}